home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / include / dbus-1.0 / dbus / dbus-python.h
C/C++ Source or Header  |  2008-06-12  |  4KB  |  103 lines

  1. /* C API for _dbus_bindings, used by _dbus_glib_bindings and any third-party
  2.  * main loop integration which might happen in future.
  3.  *
  4.  * This file is currently Python-version-independent - please keep it that way.
  5.  *
  6.  * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
  7.  *
  8.  * Permission is hereby granted, free of charge, to any person
  9.  * obtaining a copy of this software and associated documentation
  10.  * files (the "Software"), to deal in the Software without
  11.  * restriction, including without limitation the rights to use, copy,
  12.  * modify, merge, publish, distribute, sublicense, and/or sell copies
  13.  * of the Software, and to permit persons to whom the Software is
  14.  * furnished to do so, subject to the following conditions:
  15.  *
  16.  * The above copyright notice and this permission notice shall be
  17.  * included in all copies or substantial portions of the Software.
  18.  *
  19.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20.  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22.  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  23.  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  24.  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  26.  * DEALINGS IN THE SOFTWARE.
  27.  */
  28.  
  29. #ifndef DBUS_PYTHON_H
  30. #define DBUS_PYTHON_H
  31.  
  32. #include <Python.h>
  33. #define DBUS_API_SUBJECT_TO_CHANGE 1
  34. #include <dbus/dbus.h>
  35.  
  36. DBUS_BEGIN_DECLS
  37.  
  38. typedef void (*_dbus_py_func_ptr)(void);
  39.  
  40. typedef dbus_bool_t (*_dbus_py_conn_setup_func)(DBusConnection *, void *);
  41. typedef dbus_bool_t (*_dbus_py_srv_setup_func)(DBusServer *, void *);
  42. typedef void (*_dbus_py_free_func)(void *);
  43.  
  44. #define DBUS_BINDINGS_API_COUNT 3
  45.  
  46. #ifdef INSIDE_DBUS_PYTHON_BINDINGS
  47.  
  48. extern DBusConnection *DBusPyConnection_BorrowDBusConnection(PyObject *);
  49. extern PyObject *DBusPyNativeMainLoop_New4(_dbus_py_conn_setup_func,
  50.                                            _dbus_py_srv_setup_func,
  51.                                            _dbus_py_free_func,
  52.                                            void *);
  53.  
  54. #else
  55.  
  56. static PyObject *_dbus_bindings_module = NULL;
  57. static _dbus_py_func_ptr *dbus_bindings_API;
  58.  
  59. #define DBusPyConnection_BorrowDBusConnection \
  60.         (*(DBusConnection *(*)(PyObject *))dbus_bindings_API[1])
  61. #define DBusPyNativeMainLoop_New4 \
  62.     ((PyObject *(*)(_dbus_py_conn_setup_func, _dbus_py_srv_setup_func, \
  63.                     _dbus_py_free_func, void *))dbus_bindings_API[2])
  64.  
  65. static int
  66. import_dbus_bindings(const char *this_module_name)
  67. {
  68.     PyObject *c_api;
  69.     int count;
  70.  
  71.     _dbus_bindings_module = PyImport_ImportModule("_dbus_bindings");
  72.     if (!_dbus_bindings_module) {
  73.         return -1;
  74.     }
  75.     c_api = PyObject_GetAttrString(_dbus_bindings_module, "_C_API");
  76.     if (c_api == NULL) return -1;
  77.     if (PyCObject_Check(c_api)) {
  78.         dbus_bindings_API = (_dbus_py_func_ptr *)PyCObject_AsVoidPtr(c_api);
  79.     }
  80.     else {
  81.         Py_DECREF(c_api);
  82.         PyErr_SetString(PyExc_RuntimeError, "C API is not a PyCObject");
  83.         return -1;
  84.     }
  85.     Py_DECREF (c_api);
  86.     count = *(int *)dbus_bindings_API[0];
  87.     if (count < DBUS_BINDINGS_API_COUNT) {
  88.         PyErr_Format(PyExc_RuntimeError,
  89.                      "_dbus_bindings has API version %d but %s needs "
  90.                      "_dbus_bindings API version at least %d",
  91.                      count, this_module_name,
  92.                      DBUS_BINDINGS_API_COUNT);
  93.         return -1;
  94.     }
  95.     return 0;
  96. }
  97.  
  98. #endif
  99.  
  100. DBUS_END_DECLS
  101.  
  102. #endif
  103.